<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('合同流程审批')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="col-sm-8">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-sjcontract-add" th:object="${obj}">
    	<input type="hidden" id="approvename" name="approvename" th:value="${approvename}" />
    	<div class="form-group" th:if="${obj.contractType} eq 0">
        	<label class="col-sm-2 control-label is-required">合同主体单位：</label>
        	<div class="col-sm-10">
        		<select name="ztdw" th:field="*{ztdw}" readonly class="form-control" th:with="type=${@dict.getType('sj_gongs')}">
                	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
            	</select>
            </div>
        </div>
        <div class="form-group" th:if="${obj.contractType} eq 1">
        	<label class="col-sm-2 control-label is-required">合同主体单位：</label>
        	<div class="col-sm-10">
        		<select name="ztdw" th:field="*{ztdw}" readonly class="form-control" th:with="type=${@dict.getType('sj_fbgongs')}">
                	<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
            	</select>
            </div>
        </div>
    	<div class="form-group">    
            <label class="col-sm-2 control-label">单据编号：</label>
            <div class="col-sm-4">
                <input name="orderNo" th:field="*{orderNo}" class="form-control" type="text" readonly="readonly">
            </div>
            <label class="col-sm-2 control-label">申报部门：</label>
            <div class="col-sm-4">
                <input name="dept" th:field="*{dept}" class="form-control" type="text" readonly="readonly">
            </div>
        </div>
        <div class="form-group">    
            <label class="col-sm-2 control-label">申报人：</label>
            <div class="col-sm-4">
                <input name="owner" th:field="*{owner}" class="form-control" type="text" readonly="readonly">
            </div>
            <label class="col-sm-2 control-label">附件数：</label>
            <div class="col-sm-4">
                <input name="fjs" th:field="*{fjs}" class="form-control" type="text" readonly="readonly">
            </div>
        </div>
        <div class="form-group">    
            <label class="col-sm-2 control-label">申报类别：</label>
            <div class="col-sm-4">
                <select name="type" th:field="*{type}" class="form-control" th:with="type=${@dict.getType('sj_contract_type')}" readonly="readonly">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                </select>
            </div>
            <label class="col-sm-2 control-label">项目名称：</label>
            <div class="col-sm-4">
                <input name="projectName" th:field="*{projectName}" class="form-control" type="text" readonly="readonly">
            </div>
        </div>
        <div class="form-group">    
            <label class="col-sm-2 control-label">合同金额：</label>
            <div class="col-sm-4">
                <input name="htje" th:field="*{htje}" class="form-control" type="text" readonly="readonly">
            </div>
            <label class="col-sm-2 control-label">合同金额大写：</label>
            <div class="col-sm-4">
                <input name="htjedx" th:field="*{htjedx}" class="form-control" type="text" readonly="readonly">
            </div>
        </div>
        <div class="form-group">    
            <label class="col-sm-2 control-label">项目规模：<br>(平方米)</label>
            <div class="col-sm-4">
                <input name="xmgm" th:field="*{xmgm}" class="form-control" type="text" readonly="readonly">
            </div>
            <label class="col-sm-2 control-label">项目类型：</label>
            <div class="col-sm-4">
				<select name="proType" th:field="*{proType}" class="form-control" th:with="type=${@dict.getType('sj_proType')}" readonly="readonly">
                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
        	<label class="col-sm-2 control-label">合同对方：</label>
            <div class="col-sm-4">
            	<input name="customerName" th:field="*{customerName}" class="form-control" type="text" readonly>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">工作内容：</label>
            <div class="col-sm-10">
                <textarea name="descs" class="form-control" readonly="readonly">[[*{descs}]]</textarea>
            </div> 
        </div>
        <div class="form-group">
        	<input type="hidden" id="zilwj" name="zilwj" th:field="*{zilwj}" />
            <input type="hidden" id="zilwjvo" name="zilwjvo" th:value="${zilwjvo}" />
            <label class="col-sm-2 control-label">合同文件：</label>
            <div class="col-sm-10" style="margin-top: 8px;" id="zlwjlink">
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-2 control-label">运营中心审核：</label>
            <div class="col-xs-4">
                <select class="form-control" id="yyzxsh" name="yyzxsh">
                    <option th:each="ul:${userlist}" th:value="${ul.loginName}" th:text="${ul.userName}" th:disabled="${ul.status == '1'}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">审批结果：</label>
            <div class="col-sm-4">
                <label class="radio-box">
                    <input type="radio" checked="" value="true" name="fwapprove">同意</label>
                <label class="radio-box">
                    <input type="radio" value="false" name="fwapprove">拒绝</label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label is-required">审批意见：</label>
            <div class="col-sm-10">
                <textarea rows="5" name="fwshyj" class="form-control" required></textarea>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-3 col-sm-offset-3">
                <input type="hidden"  name="taskid" id="taskid" th:value="${taskid}">
                <input type="hidden"  name="status" id="status" th:value="2">
                <input type="hidden"  name="id" id="id" th:value="${obj.id}">
                <button class="btn btn-primary" onclick="submitHandler()" type="button"><i class="fa fa-check"></i>&nbsp;提交</button>
            </div>
        </div>
    </form>
</div>
</div>
<div id="ibox-content" class="col-sm-4">
    <div id="vertical-timeline" class="vertical-container dark-timeline">
    </div>
</div>
</body>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script th:inline="javascript">
    var prefix = ctx + "task/manage"
    $("#form-sjcontract-add").validate({
        focusCleanup: true
    });

    function submitHandler() {
    	if ($.validate.form()) {
        var taskid = $("#taskid").val();
        var check = document.querySelector("input[name='fwapprove']:checked").value;
        if(check=="false"){
            $("#status").val(4);
         }else{
            $("#status").val(2);
         }
        var comment = $("textarea[name=fwshyj]").val();
        
        $.operate.save("edit", $('#form-sjcontract-add').serialize(), function(){
        	var json = {"fwapprove": check, "yyxz": $("#yyzxsh").val(), "comment": comment};
	        $.ajax({
	            url : prefix + "/completeTask/" + taskid,
	            type : "POST",
	            data : JSON.stringify(json), //转JSON字符串
	            dataType: 'json',
	            contentType:'application/json;charset=UTF-8', //contentType很重要
	            success : function(result) {
	                $.modal.msg("办理成功");
	                const parent = window.parent;
	                // 我的待办
	                const myToDoIframe = parent.document.querySelector("iframe[src='/task/manage/mytask']");
	                // 我的全部待办
	                const myAllToDoIframe = parent.document.querySelector("iframe[src='/task/manage/alltasks']");
	                myToDoIframe && myToDoIframe.contentWindow.location.reload(true);
	                myAllToDoIframe && myAllToDoIframe.contentWindow.location.reload(true);
	                $.modal.closeTab();
	            }
	        });
	        
        });
    	}
    }

    $(document).ready(function(){
        // 获取时间轴
        $.get(prefix + "/history/" + $("#taskid").val(), function(data){
            for (var a = 0; a < data.length ; a++) {
                $("#vertical-timeline").append("<div class=\"vertical-timeline-block\"><div class=\"vertical-timeline-icon lazur-bg\">" +
                    "<i class=\"fa fa-briefcase\"></i></div>" +
                    "<div class=\"vertical-timeline-content\">" +
                    "<span class=\"vertical-date\">开始 <small>" + data[a].startTime + "</small></span><br>" +
                    "<h2><b>" + data[a].assignee + ":</b>" + data[a].taskName + "</h2>" +
                    "<p>" + (data[a].comment || "-") + "</p>" +
                    "<span class=\"vertical-date\">结束 <small>" + (data[a].endTime || "-") + "</small></span>" +
                    "</div>" +
                    "</div>");
            }
        });
    });
    
    $(function() {
		var zilwj = $("#zilwjvo").val();
    	
    	var n=zilwj.split(",");
    	for(var i=0;i<n.length;i++){
//     		var url = "http://lkgnews.cn:8012/onlinePreview?url="+encodeURIComponent(Base64.encode(n[i]));
    		var url = n[i];
    		$("#zlwjlink").append("<a href='"+url+"' target='_blank' >"+n[i]+"</a><br>");
    	}
    	
    });
</script>
</body>
</html>